home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / pingpong.c < prev    next >
C/C++ Source or Header  |  1998-07-18  |  5KB  |  164 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. /* This is strange; it's unlikely that the sprites actually have a hardware */
  15. /* clipping region, but I haven't found another way to have them masked by */
  16. /* the characters at the top and bottom of the screen. */
  17. static struct rectangle spritevisiblearea =
  18. {
  19.     0*8, 32*8-1,
  20.     4*8, 29*8-1
  21. };
  22.  
  23.  
  24.  
  25. /***************************************************************************
  26.  
  27.   Convert the color PROMs into a more useable format.
  28.  
  29.   Ping Pong has a 32 bytes palette PROM and two 256 bytes color lookup table
  30.   PROMs (one for sprites, one for characters).
  31.   I don't know for sure how the palette PROM is connected to the RGB output,
  32.   but it's probably the usual:
  33.  
  34.   bit 7 -- 220 ohm resistor  -- BLUE
  35.         -- 470 ohm resistor  -- BLUE
  36.         -- 220 ohm resistor  -- GREEN
  37.         -- 470 ohm resistor  -- GREEN
  38.         -- 1  kohm resistor  -- GREEN
  39.         -- 220 ohm resistor  -- RED
  40.         -- 470 ohm resistor  -- RED
  41.   bit 0 -- 1  kohm resistor  -- RED
  42.  
  43. ***************************************************************************/
  44. void pingpong_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  45. {
  46.     int i;
  47.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  48.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  49.  
  50.     for (i = 0;i < Machine->drv->total_colors;i++)
  51.     {
  52.         int bit0,bit1,bit2;
  53.  
  54.         /* red component */
  55.         bit0 = (*color_prom >> 0) & 0x01;
  56.         bit1 = (*color_prom >> 1) & 0x01;
  57.         bit2 = (*color_prom >> 2) & 0x01;
  58.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  59.         /* green component */
  60.         bit0 = (*color_prom >> 3) & 0x01;
  61.         bit1 = (*color_prom >> 4) & 0x01;
  62.         bit2 = (*color_prom >> 5) & 0x01;
  63.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  64.         /* blue component */
  65.         bit0 = 0;
  66.         bit1 = (*color_prom >> 6) & 0x01;
  67.         bit2 = (*color_prom >> 7) & 0x01;
  68.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  69.  
  70.         color_prom++;
  71.     }
  72.  
  73.     /* color_prom now points to the beginning of the char lookup table */
  74.  
  75.     /* sprites */
  76.     for (i = 0;i < TOTAL_COLORS(1);i++)
  77.     {
  78.         int code;
  79.         int bit0,bit1,bit2,bit3;
  80.  
  81.         /* the bits of the color code are in reverse order - 0123 instead of 3210 */
  82.         code = *(color_prom++) & 0x0f;
  83.         bit0 = (code >> 0) & 1;
  84.         bit1 = (code >> 1) & 1;
  85.         bit2 = (code >> 2) & 1;
  86.         bit3 = (code >> 3) & 1;
  87.         code = (bit0 << 3) | (bit1 << 2) | (bit2 << 1) | (bit3 << 0);
  88.         COLOR(1,i) = code;
  89.     }
  90.  
  91.     /* characters */
  92.     for (i = 0;i < TOTAL_COLORS(0);i++)
  93.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
  94. }
  95.  
  96.  
  97.  
  98. /***************************************************************************
  99.  
  100.   Draw the game screen in the given osd_bitmap.
  101.  
  102. ***************************************************************************/
  103. void pingpong_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  104. {
  105.     int offs;
  106.  
  107.  
  108.     /* for every character in the Video RAM, check if it has been modified */
  109.     /* since last time and update it accordingly. */
  110.     for (offs = videoram_size - 1;offs >= 0;offs--)
  111.     {
  112.         if (dirtybuffer[offs])
  113.         {
  114.             int sx,sy,flipx,flipy,tchar,color;
  115.  
  116.  
  117.             sx = offs % 32;
  118.             sy = offs / 32;
  119.  
  120.             dirtybuffer[offs] = 0;
  121.  
  122.             flipx = colorram[offs] & 0x40;
  123.             flipy = colorram[offs] & 0x80;
  124.             color = colorram[offs] & 0x1F;
  125.             tchar = (videoram[offs] + ((colorram[offs] & 0x20)<<3));
  126.  
  127.             drawgfx(tmpbitmap,Machine->gfx[0],
  128.                     tchar,
  129.                     color,
  130.                     flipx,flipy,
  131.                     8 * sx,8 * sy,
  132.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  133.         }
  134.     }
  135.  
  136.  
  137.     /* copy the character mapped graphics */
  138.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  139.  
  140.  
  141.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  142.     /* order, to have the correct priorities. */
  143.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  144.     {
  145.         int sx,sy,flipx,flipy,color,schar;
  146.  
  147.  
  148.         sx = spriteram[offs + 3];
  149.         sy = 241 - spriteram[offs + 1];
  150.  
  151.         flipx = spriteram[offs] & 0x40;
  152.         flipy = spriteram[offs] & 0x80;
  153.         color = spriteram[offs] & 0x1F;
  154.         schar = spriteram[offs + 2] & 0x7F;
  155.  
  156.         drawgfx(bitmap,Machine->gfx[1],
  157.                 schar,
  158.                 color,
  159.                 flipx,flipy,
  160.                 sx,sy,
  161.                 &spritevisiblearea,TRANSPARENCY_COLOR,0);
  162.     }
  163. }
  164.